package cn.com.czpb.client.module.subscribe.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import cn.com.czpb.client.R;
import cn.com.czpb.client.model.news.NewsBean;
import cn.com.czpb.client.model.subscribe.MySubscribeNewsbean;
import cn.com.czpb.client.utils.StringUtils;

import java.util.List;

/**
 * Created by 猪猪侠 on 2017/7/3.
 */

public class SubscribeMyAdapterNew extends BaseMultiItemQuickAdapter<NewsBean, BaseViewHolder> {
    private boolean flag = true;
    private String type;//是否加载图片

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public SubscribeMyAdapterNew(List<NewsBean> data, boolean flag, String type) {
        super(data);
        this.flag = flag;
        this.type = type;
        addItemType(MySubscribeNewsbean.THREEPIC, R.layout.news_3_item_layout);
        addItemType(MySubscribeNewsbean.LEFTPIC, R.layout.news_list_item_layout);
        addItemType(MySubscribeNewsbean.NOPIC, R.layout.news_list_item_nopic_layout);
        addItemType(MySubscribeNewsbean.BIGPIC, R.layout.news_list_bigitem_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, NewsBean item) {
        switch (helper.getItemViewType()) {
            case MySubscribeNewsbean.THREEPIC://三联图
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title, item.getTitle());//title
                helper.setText(R.id.newsitem_copyfrom, item.getCopyfrom());
                helper.setText(R.id.comment_num_id, item.getComcount() + "跟帖");//评论数量
                helper.setText(R.id.praise_num_id,item.getPraisecount());//点赞数
                helper.setText(R.id.tv_time_id, item.getUpdateTime());//时间
                List<String> imgs = item.getImgs();
                if (type.equals("0")) {
                    if (imgs != null && imgs.size() > 0) {
                        Glide.with(mContext).load(imgs.get(0)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item1));
                        if (imgs.size() > 1) {
                            Glide.with(mContext).load(imgs.get(1)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item2));
                            if (imgs.size() > 2) {
                                Glide.with(mContext).load(imgs.get(2)).crossFade().placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.news_3_item3));
                            }
                        }
                    }
                }
                if (!StringUtils.isEmpty(item.getMediaName())){
                    helper.setVisible(R.id.img_newstype_id,true);
                    helper.setText(R.id.img_newstype_id, item.getMediaName());//title
                }else{
                    helper.setVisible(R.id.img_newstype_id,false);
                }
                break;
            case MySubscribeNewsbean.LEFTPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title, item.getTitle());//title
                helper.setText(R.id.newsitem_copyfrom, item.getCopyfrom());//copyfrom
                helper.setText(R.id.comment_num_id, item.getComcount() + "跟帖");//跟帖数
                helper.setText(R.id.praise_num_id,item.getPraisecount());//点赞数
                helper.setText(R.id.tv_time_id, item.getUpdateTime());//时间
//                Glide.with(mContext).load(item.getNewsflag()).crossFade().into((ImageView) helper.getView(R.id.img_newstype_id));
                //视频 展示视频标签
                if ("6".equals(item.getRtype())) {
                    helper.setVisible(R.id.img_play_id, true);
                } else {
                    helper.setVisible(R.id.img_play_id, false);
                }
                if (type.equals("0")) {
                    if (helper.getView(R.id.newsitem_img).getVisibility() == View.VISIBLE
                            && null != item.getImgs()
                            && item.getImgs().size() > 0) {
                        Glide.with(mContext).load(item.getImgs().get(0)).crossFade()
                                .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                    } else {
                        Glide.with(mContext).load("").crossFade()
                                .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                    }
                }
                if (!StringUtils.isEmpty(item.getMediaName())){
                    helper.setVisible(R.id.img_newstype_id,true);
                    helper.setText(R.id.img_newstype_id, item.getMediaName());//title
                }else{
                    helper.setVisible(R.id.img_newstype_id,false);
                }
                break;

            case MySubscribeNewsbean.NOPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title, item.getTitle());//title
                helper.setText(R.id.newsitem_copyfrom, item.getCopyfrom());
                helper.setText(R.id.comment_num_id, item.getComcount() + "跟帖");//评论数量
                helper.setText(R.id.praise_num_id,item.getPraisecount());//点赞数
                helper.setText(R.id.tv_time_id, item.getUpdateTime());//时间
                if (!StringUtils.isEmpty(item.getMediaName())){
                    helper.setVisible(R.id.img_newstype_id,true);
                    helper.setText(R.id.img_newstype_id, item.getMediaName());//title
                }else{
                    helper.setVisible(R.id.img_newstype_id,false);
                }
                break;
            case MySubscribeNewsbean.BIGPIC:
                helper.addOnClickListener(R.id.newsItem_root);
                helper.setText(R.id.newsitem_title, item.getTitle());//title
                helper.setText(R.id.newsitem_copyfrom, item.getCopyfrom());//copyfrom
                helper.setText(R.id.comment_num_id, item.getComcount() + "跟帖");//跟帖数
                helper.setText(R.id.praise_num_id,item.getPraisecount());//点赞数
                helper.setText(R.id.tv_time_id, item.getUpdateTime());//时间
//                Glide.with(mContext).load(item.getNewsflag()).crossFade().into((ImageView) helper.getView(R.id.img_newstype_id));
                //视频 展示视频标签
                if ("6".equals(item.getRtype())) {
                    helper.setVisible(R.id.img_play_id, true);
                } else {
                    helper.setVisible(R.id.img_play_id, false);
                }
                if (type.equals("0")) {
                    Glide.with(mContext).load(item.getImgs().get(0)).crossFade()
                            .placeholder(R.drawable.default_bg).into((ImageView) helper.getView(R.id.newsitem_img));
                }
                if (!StringUtils.isEmpty(item.getMediaName())){
                    helper.setVisible(R.id.img_newstype_id,true);
                    helper.setText(R.id.img_newstype_id, item.getMediaName());//title
                }else{
                    helper.setVisible(R.id.img_newstype_id,false);
                }
                break;

        }
    }
}
